#include "radarform.h"
#include "ui_radarform.h"

RadarForm::RadarForm(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::RadarForm)
{
    ui->setupUi(this);
    this->InitTreeView();
}

RadarForm::~RadarForm()
{
    delete ui;
}

void RadarForm::InitTreeView()
{
    ui->tableView_2->setWindowTitle("数据列表");
    ui->tableView_2->setWindowIconText("数据列表");
    m_model.setRowCount(0);
    m_model.setColumnCount(6);
    m_model.setHorizontalHeaderLabels(QStringList() << "采集时间"
                                                    << "镜筒温度"<<"环境温度"
                                                    <<"环境湿度"<<"水平角度"<<"俯仰角度");

    QHeaderView *headerView = ui->tableView_2->horizontalHeader();
    // 设置样式表，包括背景颜色和字体样式
    headerView->setSectionResizeMode(QHeaderView::ResizeMode::Stretch);
    headerView->setStyleSheet("QHeaderView::section { background-color: #8da1ff; color: white }");
    headerView->setTextElideMode(Qt::TextElideMode::ElideMiddle);

    ui->tableView_2->setModel(&m_model);

    /*
    connect(this, &VisibilityMeterForm::updateView, this, [&](VisibilityProtocol point){
        int row = m_model.rowCount();
        if(row == 10){
            m_model.removeRows(0, 1);
            row--;
        }

        auto item = new QStandardItem(QString::asprintf("%d",point.one_minute_visibility));
        item->setTextAlignment(Qt::AlignCenter);
        m_model.setItem(row, 0, item);

        item = new QStandardItem(QString::asprintf("%d",point.ten_minute_visibility));
        item->setTextAlignment(Qt::AlignCenter);
        m_model.setItem(row, 1, item);

        item = new QStandardItem(QString::asprintf("%d",point.TheIntensityOfEmittedEnergy));
        item->setTextAlignment(Qt::AlignCenter);
        m_model.setItem(row, 2, item);

        item = new QStandardItem(QString::asprintf("%d",point.TheIntensityOfReceivedEnergy));
        item->setTextAlignment(Qt::AlignCenter);
        m_model.setItem(row, 3, item);

        item = new QStandardItem(point.device_code);
        item->setTextAlignment(Qt::AlignCenter);
        m_model.setItem(row, 4, item);

        item = new QStandardItem(point.date_time.toString("yyyy/MM/dd HH:mm:ss"));
        item->setTextAlignment(Qt::AlignCenter);
        m_model.setItem(row, 5, item);

        ui->tableView->update();
    });
*/
}
